package com.nmsl.system.medical_temp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.system.medical_temp.domain.MedicalTemplate;
import com.nmsl.system.medical_temp.service.IMedicalTemplateService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 病例模板Controller
 * 
 * @author gmh
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/system/medical_temp")
public class MedicalTemplateController extends BaseController
{
    @Autowired
    private IMedicalTemplateService medicalTemplateService;

    /**
     * 查询病例模板列表
     */

    @PreAuthorize("@ss.hasPermi('system:medical_temp:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalTemplate medicalTemplate)
    {
        startPage();
        List<MedicalTemplate> list = medicalTemplateService.selectMedicalTemplateList(medicalTemplate);
        return getDataTable(list);
    }

    /**
     * 导出病例模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:medical_temp:export')")
    @Log(title = "病例模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalTemplate medicalTemplate)
    {
        List<MedicalTemplate> list = medicalTemplateService.selectMedicalTemplateList(medicalTemplate);
        ExcelUtil<MedicalTemplate> util = new ExcelUtil<MedicalTemplate>(MedicalTemplate.class);
        util.exportExcel(response, list, "病例模板数据");
    }

    /**
     * 获取病例模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:medical_temp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicalTemplateService.selectMedicalTemplateById(id));
    }

    /**
     * 新增病例模板
     */
    @PreAuthorize("@ss.hasPermi('system:medical_temp:add')")
    @Log(title = "病例模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalTemplate medicalTemplate)
    {
        return toAjax(medicalTemplateService.insertMedicalTemplate(medicalTemplate));
    }

    /**
     * 修改病例模板
     */

    @PreAuthorize("@ss.hasPermi('system:medical_temp:edit')")
    @Log(title = "病例模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalTemplate medicalTemplate)
    {
        return toAjax(medicalTemplateService.updateMedicalTemplate(medicalTemplate));
    }

    /**
     * 删除病例模板
     */
    @PreAuthorize("@ss.hasPermi('system:medical_temp:remove')")
    @Log(title = "病例模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicalTemplateService.deleteMedicalTemplateByIds(ids));
    }
    //调用病例模板
    @PreAuthorize("@ss.hasPermi('system:medical_temp:list')")
    @GetMapping("/getBingliInfo")
    public AjaxResult selectHistory(Long id)
    {
        return success(medicalTemplateService.selectHistoryByTempId(id));
    }



}
